﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RabbitMQ.Client;

namespace _012_RabbitMQClient
{
    class Program
    {
        static void Main(string[] args)
        {
            var factory = new ConnectionFactory() { HostName = "ds-macbook-pro", Port=5672, UserName="admin", Password="admin" };

            using (var connection = factory.CreateConnection())
            {
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare(queue: "hello",
                        durable: false,
                        exclusive: false,
                        autoDelete: false,
                        arguments: null);

                    Console.WriteLine("[x] Start message sending ..");
                    DateTime start = DateTime.Now;
                    for (int i = 0; i < 1000000; i++)
                    {
                        string message = "Hello world!";

                        var body = Encoding.UTF8.GetBytes(message);

                        channel.BasicPublish(exchange: "",
                            routingKey: "hello",
                            basicProperties: null,
                            body: body);
                    }
                    TimeSpan duration = DateTime.Now - start;
                    Console.WriteLine("[x] Message sent '{0}'", duration.Seconds);
                }
            }
            Console.WriteLine("Press enter");
            Console.ReadLine();
        }
    }
}
